#include "sidebarwidget.h"
#include <QVBoxLayout>
#include <QRadioButton>
#include <QPushButton>
#include <QFile>
#include <QButtonGroup>
#include "configargs.h"

SidebarWidget::SidebarWidget(QWidget *parent) : QWidget(parent)
{
    m_pBtnGrounp = new QButtonGroup();

    QRadioButton *pUserBtn = new QRadioButton();
    QRadioButton *pDesktopBtn = new QRadioButton();
    QRadioButton *pGameBtn = new QRadioButton();
    QRadioButton *pSettingBtn = new QRadioButton();
    QPushButton *pLockBtn = new QPushButton();

    m_pBtnGrounp->addButton(pUserBtn, 0); //0 shi id
    m_pBtnGrounp->addButton(pDesktopBtn, 1);
    m_pBtnGrounp->addButton(pGameBtn, 2);
    m_pBtnGrounp->addButton(pSettingBtn, 3);

    QVBoxLayout *pMainLayout = new QVBoxLayout();
    pMainLayout->setMargin(10);
    pMainLayout->setSpacing(10);

    pMainLayout->addWidget(pUserBtn);
    pMainLayout->addSpacing(10);
    pMainLayout->addWidget(pDesktopBtn);
    pMainLayout->addWidget(pGameBtn);
    pMainLayout->addWidget(pSettingBtn);
    pMainLayout->addStretch(1);
    pMainLayout->addWidget(pLockBtn);

    this->setLayout(pMainLayout);

    pUserBtn->setObjectName("userBtn");
    pDesktopBtn->setObjectName("desktopBtn");
    pGameBtn->setObjectName("gameBtn");
    pSettingBtn->setObjectName("settingBtn");
    pLockBtn->setObjectName("lockBtn");

    pUserBtn->setFocusPolicy(Qt::NoFocus);
    pDesktopBtn->setFocusPolicy(Qt::NoFocus);
    pGameBtn->setFocusPolicy(Qt::NoFocus);
    pSettingBtn->setFocusPolicy(Qt::NoFocus);
    pLockBtn->setFocusPolicy(Qt::NoFocus);

    pDesktopBtn->setChecked(true); // mo ren sheng xiao button

    loadQss();

    connect(pUserBtn, SIGNAL(clicked(bool)), this, SIGNAL(userBtnChecked()));
    connect(pDesktopBtn, SIGNAL(clicked(bool)), this, SIGNAL(desktopBtnChecked()));
    connect(pGameBtn, SIGNAL(clicked(bool)), this, SIGNAL(gamesBtnChecked()));
    connect(pSettingBtn, SIGNAL(clicked(bool)), this, SIGNAL(settingBtnChecked()));

    connect(pLockBtn, SIGNAL(clicked(bool)), this, SIGNAL(lockBtnClicked()));
}

void SidebarWidget::slotRadioBtnChecked()
{
    switch(m_pBtnGrounp->checkedId()) {
    case 0: {
        emit userBtnChecked();
    }break;
    case 1: {
        emit desktopBtnChecked();
    }break;
    case 2: {
     //   emit gameBtnChecked();
    }break;
    case 3: {
        emit settingBtnChecked();
    }break;
    }
}

void SidebarWidget::loadQss()
{
	QString iconQssStr;
	QString sizeQssStr;
	QFile sizeQss;
	
	QFile iconQss(":/qss/linuxdesktop/stylesheet/sidebaricon.qss");
	iconQss.open(QFile::ReadOnly);
	iconQssStr = iconQss.readAll();

	if(g_lcdsize == LCDSIZE_480x272)	//if is 4.3 inch
	{	
		qDebug("using 4.3 inch");
		sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/sidebarsize_480x272.qss");
		sizeQss.open(QFile::ReadOnly);
		sizeQssStr = sizeQss.readAll();
	}else{
		sizeQss.setFileName(":/qss/linuxdesktop/stylesheet/sidebarsize.qss");
		sizeQss.open(QFile::ReadOnly);
		sizeQssStr = sizeQss.readAll();
	}
	
    this->setStyleSheet(sizeQssStr + iconQssStr);
}
